package cn.bdqn.controller;

import cn.bdqn.dto.Dto;
import cn.bdqn.pojo.ItripAreaDic;
import cn.bdqn.pojo.ItripHotelOrder;
import cn.bdqn.pojo.ItripLabelDic;
import cn.bdqn.service.HotelService;
import cn.bdqn.util.VerificationToken;
import cn.bdqn.vo.ItripAreaDicVO;
import cn.bdqn.vo.ItripLabelDicVO;
import cn.bdqn.vo.ItripSearchDetailsHotelVO;
import cn.bdqn.vo.ItripSearchFacilitiesHotelVO;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
public class HotelController {
    @Resource
private HotelService hotelService;

    /**
     *查看所有酒店特色
     * @param linkPhone ， pageNo （两个参数都可以空来查询所有用户）
     * @return
     */
    @ApiOperation(value = "查询所有特色", httpMethod = "GET",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "无条件查询")
    @RequestMapping(value = "/api/hotel/queryhotelfeature", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Dto selectHotelByFeature(){
        Dto dto=new Dto();
        Map map=new HashMap<>();
        List<ItripLabelDicVO> itripAreaDicVOs=new ArrayList<>(0);
        List<ItripLabelDic> list=hotelService.selectLabelAllMessage(map);
        if(list.size()>0){
            dto.setCode("0");
            dto.setMsg("查询成功");
        }
        for(ItripLabelDic i:list){
            ItripLabelDicVO itripLabelDicVO =new ItripLabelDicVO();
            itripLabelDicVO.setId(i.getId());
            itripLabelDicVO.setName(i.getName());
            itripLabelDicVO.setDescription(i.getDescription());
            itripLabelDicVO.setPic(i.getPic());
            itripAreaDicVOs.add(itripLabelDicVO);
        }
        dto.setData(itripAreaDicVOs);
        return dto;
    }


    /**
     *查看所有热门城市
     * @param linkPhone ， pageNo （两个参数都可以空来查询所有用户）
     * @return
     */
    @ApiOperation(value = "查看所有热门城市", httpMethod = "GET",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "无条件查询")
    @RequestMapping(value = "/api/hotel/queryhotcity/{type}", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Dto selectHotCity(@PathVariable Integer type){
        Dto dto=new Dto();
        Map map=new HashMap();
        map.put("type",type);
        List<ItripAreaDic> list =hotelService.selectAreaAllMessage(map);
        List<ItripAreaDicVO> list1=new ArrayList<>(0);
        if(list.size()>0){
            dto.setCode("0");
            dto.setMsg("查询成功");
        }
        for(ItripAreaDic i:list){
            ItripAreaDicVO itripAreaDicVO =new ItripAreaDicVO();
            itripAreaDicVO.setId(i.getId());
            itripAreaDicVO.setName(i.getName());
            list1.add(itripAreaDicVO);
        }
        dto.setData(list1);
           return dto;
    }

    /**
     *查看所有酒店特色
     * @param linkPhone ， pageNo （两个参数都可以空来查询所有用户）
     * @return
     */
    @ApiOperation(value = "查询所有商圈", httpMethod = "GET",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "通过城市id来查询商圈")
    @RequestMapping(value = "/api/hotel/querytradearea/{cityId}", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Dto selectAllAreaByCityId(@PathVariable Integer cityId){
        Dto dto=new Dto();
       Map map=new HashMap();
       map.put("cityId",cityId);
        List<ItripAreaDic> list=hotelService.selectAreaByCityId(map);
        List<ItripAreaDicVO> list1=new ArrayList<>(0);
        if(list.size()>0){
            dto.setCode("0");
            dto.setMsg("查询成功");
        }else{
            dto.setCode("0");
            dto.setMsg("没有查询到信息");
            dto.setData(null);
        }
        for(ItripAreaDic i:list){
            ItripAreaDicVO itripAreaDicVO =new ItripAreaDicVO();
            itripAreaDicVO.setId(i.getId());
            itripAreaDicVO.setName(i.getName());
            list1.add(itripAreaDicVO);
        }
        dto.setData(list1);
        return dto;
    }

    @RequestMapping(value = "/api/hotel/queryhoteldetails/{id}", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public Dto  queryHotelDetails(@PathVariable Long id){
        Dto dto=new Dto();
        List<ItripSearchDetailsHotelVO> itripSearchDetailsHotelVOList = null;
        try {
            if(id==null){
                dto.setCode("10086");
                dto.setMsg("酒店ID不能为空");
                return dto;
            }
            itripSearchDetailsHotelVOList = hotelService.getHotelDetails(id);
            dto.setData(itripSearchDetailsHotelVOList);
            return dto;
        } catch (Exception e) {
            e.printStackTrace();
            dto.setMsg("系统异常");
            dto.setCode("10086");
            return dto;
        }
    }

    @RequestMapping(value = "/api/hotel/queryhotelfacilities/{id}", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public Dto queryHotelFacilities(@PathVariable Long id){
        Dto dto=new Dto();
        ItripSearchFacilitiesHotelVO itripSearchFacilitiesHotelVO = null;
        try {
            if(id==null){
                dto.setCode("10086");
                dto.setMsg("酒店ID不能为空");
                return dto;
            }
            itripSearchFacilitiesHotelVO = hotelService.findItripHotelFacilitiesById(id);
            dto.setData(itripSearchFacilitiesHotelVO.getFacilities());
            return dto;
        } catch (Exception e) {
            e.printStackTrace();
            dto.setMsg("系统异常 ");
            dto.setCode("10086");
            return dto;
        }
    }


}
